import { UserService } from './user.service';
import { Resolver, Query, Args, Mutation, Context } from '@nestjs/graphql';
import { User } from '../../graphql.schema';
import { LoginDto } from './dto/login.dto';
import { Req, UseGuards } from '@nestjs/common';
import { Request } from 'express';
import { AuthGuard } from '@nestjs/passport';
import { GqlAuthGuard } from '@/common/gql-auth.guard';

@Resolver()
export class UserReolver {
  constructor(private readonly userService: UserService) {}

  @Query()
  async users(): Promise<User[]> {
    return this.userService.getUsers();
  }

  @Query()
  async user(@Args('id') id: string) {
    return this.userService.findUserById(id);
  }

  @Query()
  @UseGuards(GqlAuthGuard)
  async currentUser(@Context() ctx: any): Promise<User> {
    return ctx.req.user;
  }

  @Mutation()
  async signUp(@Args() login: LoginDto) {
    return this.userService.signUp(login);
  }

  @Mutation()
  async signIn(@Args() login: LoginDto) {
    return this.userService.signIn(login);
  }
}
